<?php

namespace app\api\controller;
use app\api\controller\Member;
class Base
{

    //注册功能
    public function register()
    {
        //传入学号，姓名，密码注册
        $id = input('get.id');
        $name = input('get.name');
        $password = input('get.password');
        if (empty($id) || empty($name) || empty($password)){
            output_error('请填写完整信息');
            output_error('学号活姓名或密码为空，请填写完整信息');
        }
        //规则1：学号唯一
        $data = Member::where('member_id' , '=' ,$id)->find();
        if(!empty($data));

        //规则2：密码md5加密
        $data = array();
        $data['member_id'] = $id;
        $data['member_name'] = $name;
        $data['member_password'] = md5($password);
        $data['member_token'] = '1';
        $data['member_gender'] = '1';
        $data['add_time'] = time();
        Member::insert($data);
        output_data('1');

    }

    //找回密码
    public function findpass()
    {
        //通过学号，姓名重置密码
        $id = input('get.id');
        $name = input('get.name');
        $password = input('get.password');
        if (empty($id) || empty($name) || empty($password)) {
            output_error('请填写完整信息');
        }
        //规则1：密码md5加密
    }

    //登录功能
    public function login()
    {
        //通过学号，密码登录，返回Token
        $id = input('get.id');
        $name = input('get.name');
        $password = input('get.password');
        if (empty($id) || empty($name) || empty($password)) {
            output_error('请填写完整信息');

            $condition = array();
            $condition [] = ['member_id','='.$id];
            $condition[] = ['member_password','=',md5($password)];
            $data = Member::where($condition)->find();
            if (empty($data))output_error('学号密码不匹配');
        }

        //规则1：token由学号+当前时间戳md5加密生成
    }

}
